
from django.views import View

from User.models import OrderVip, OrderGoods, OrderRent
from Venue.models import Vip, Goods
from sportsground.utils import Req
from sportsground.utils.Res import Res
from sportsground.utils.views import LoginRequiredVenue


class VerifyRentView(LoginRequiredVenue, View):
    """ 租赁验证 """

    @Req.getJson
    def post(self, request):
        """ 添加 """
        orderRentId = request.json_dict.get('orderRentId')
        verify = request.json_dict.get('verify','')

        venue = request.user.venue

        orderRent = OrderRent.objects.filter(id=orderRentId).first()
        if not orderRent:
            return Res.Json(Res.ParamErr)

        if orderRent.getTime:
            return Res.Json(Res.Warn, msg="已校验")
        if not orderRent.verifyCode(verify):
            return Res.Json(Res.Warn, msg="校验码错误")

        return Res.Json(Res.OK)
